home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_1 / brandnewwais.pl < prev    next >
Perl Script  |  1996-03-21  |  7KB  |  269 lines

  1. #!./perl
  2. #
  3. # newwais.pl -- WAIS search interface
  4. #
  5. # from wais.pl
  6. #
  7. # Tony Sanders <sanders@bsdi.com>, Nov 1993
  8. #
  9. # Example configuration (in local.conf):
  10. #     map topdir wais.pl &do_wais($top, $path, $query, "database", "title")
  11. #
  12. # this script uses a sneaky feature of Mosaic that interpretes a 
  13. # single text input form with the name 'isindex' (case sensitive) to
  14. # the same as a <ISINDEX>.  On non-mosaic clients, you wind up with an
  15. # additional query
  16. #
  17. # Note that I know even less about perl than the other two people
  18. # who hacked this, so feel free to send hate mail to pjh@netcom.com
  19. # if I did something really bad (or if there is a better way of
  20. # grabbing the filename off the end of a path.
  21. #
  22. #
  23.  
  24. # parse disc name from ServerName Environt Variable with this script
  25.  
  26. do './variables.pl';
  27.  
  28. &get_request;
  29.  
  30. $oldLIB = $ENV{"LD_LIBRARY_PATH"}; 
  31. $ENV{"LD_LIBRARY_PATH"} = "$oldLIB:/usr/ucblib"; 
  32.  
  33.  
  34. #require 'ctime.pl';
  35.  
  36. $waisq = "./waisq";
  37. $waisd = "/tmp/.wais/wais_$disc_name";
  38.  
  39.  
  40. $src = "wais_$disc_name";
  41. $title = "Example Data";
  42. #
  43. # file type map based on file extension, since all file types
  44. # come back type URL
  45. #
  46.  
  47. %filetype = (
  48. 'html', 'HTML File', 'ps', 'PostScript  Document',
  49. 'htm', 'HTML File', 'eps', 'PostScript  Document',
  50. 'txt','Text File', 'home', ''
  51. );
  52. $filetype{home}="Home page on $disc_name";
  53.  
  54. open(IN,"/tmp/httpd/.products/.bin/real_names.txt") || die "howdy";
  55.      while (<IN>) {
  56.         @tmp = split(/    /,$_);
  57.         $dir = @tmp[0];
  58.         $realname = @tmp[1];
  59.     #print "test $dir   $realname\n";
  60.     $real_name{$dir} = $realname;
  61.      }
  62. close(IN);
  63.  
  64. #
  65. # code
  66. sub get_request {
  67.  
  68.     if ($ENV{'REQUEST_METHOD'} eq "POST") {
  69.         read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
  70.     } elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
  71.         $request = $ENV{'QUERY_STRING'};
  72.     }
  73.  
  74.  
  75.     @names = &url_decode(split(/[&=]/, $request));
  76.     %rqpairs = @names;
  77.  
  78. }
  79.  
  80. sub url_decode {
  81.  
  82. #       Decode a URL encoded string or array of strings
  83. #               + -> space
  84. #               %xx -> character xx
  85.  
  86.  
  87.     foreach (@_) {
  88.         tr/+/ /;
  89.         s/%(..)/pack("c",hex($1))/ge;
  90.     }
  91.     @_;
  92. }
  93.  
  94. sub send_index {
  95.     print "Content-type: text/html\n\n";
  96.     
  97.     print "<HEAD>\n<TITLE>Index of ", $title, "</TITLE>\n</HEAD>\n";
  98.     print "<BODY  bgcolor=\"#DDDDDD\">\n<H1>", $title, "</H1>\n";
  99.  
  100.     print "This is an index of the information on this server. Please\n";
  101.     print "type a query in the search dialog.\n<P>";
  102.     print "You may use compound searches, such as: <CODE>environment AND cgi</CODE>\n";
  103.     print "<ISINDEX>";
  104. }
  105.  
  106.  
  107. sub do_wais {
  108. #    local($top, $path, $query, $src, $title) = @_;
  109.  
  110.  
  111.  
  112. #    for (@_){s/\\//g};
  113.  
  114.     local(@query) = $rqpairs{"isindex"};
  115.     
  116.     local($pquery) = join(" ", @query);
  117.     local($nquery) = $pquery;
  118.     $nquery =~ tr/[A-Z]/[a-z]/;
  119.     if (!(($nquery =~ / and /) || ($nquery =~ / or /)))
  120.     {
  121.        $nquery =~ s/ //g;
  122.     }
  123.     $nquery = $request;
  124. #
  125. # grab a wais source if there is one
  126. #
  127.  
  128.     local($test) = $ENV{'PATH_INFO'};
  129.     if ($test)
  130.     {
  131.     $test =~ s/\///;
  132.         $src = "wais_$disc_name";
  133.         $title = $test;
  134.     }
  135.  
  136.     close STDERR;
  137.     open(STDERR, ">/dev/null");
  138.  
  139.     print "Content-type: text/html\n\n";
  140.  
  141.     $ENV{'HOME'} = "/";
  142.     
  143.     open(WAISQ, "-|") || exec ($waisq, "-c", $waisd, "-m", 100,
  144.                                 "-f", "-", "-S", "$src.src", "-g", $nquery);
  145.  
  146.     print "<HEAD>\n<TITLE>Search of ", "$disc_name $disc_rest", "</TITLE>\n</HEAD>\n";
  147.     print "<img src=\"/.wais/images/goto_home.gif\">\n";
  148.     print "<BODY bgcolor=\"#DDDDDD\">\n<H1> $disc_name $disc_rest Search Results</H1>\n";
  149.  
  150.     print "<HR><FORM method=\"GET\" action=\"/cgi-bin/brandnewwais.pl/$src\">\n";
  151.     print "<h2>Enter keyword(s):\n";
  152. #    print "<input name=\"isindex\" value=\"@query\" size=30></FORM><HR>\n";
  153.     print "<input name=\"isindex\" value=\"$nquery\" size=30></FORM><HR></h2>\n";
  154.     
  155.     print "Your search found the following documents\n";
  156.     print "items relevant to <B>\`$nquery\':</B><P>\n";
  157.         print "<center>";
  158.         print "<table border=5>";
  159.     print "<DL>\n";
  160.         print "<th> Company Name</th>";
  161.         print "<th> Document Matched</th>";
  162.         print "<th> Document Type</th>";
  163.         print "<tr>\n";
  164.  
  165.  
  166.     #local($hits, $score, $headline, $lines, $bytes, $type, $date);
  167.     local($hits, $score, $lines, $bytes, $type, $date);
  168.  
  169. $hits = -1;
  170.     print "<OL>";
  171.     while (<WAISQ>) {
  172.         /:score\s+(\d+)/ && ($score = $1);
  173.         /:number-of-lines\s+(\d+)/ && ($lines = $1);
  174.         /:number-of-bytes\s+(\d+)/ && ($bytes = $1);
  175.         /:type "(.*)"/ && ($type = $1);
  176.         /:headline "(.*)"/ && ($headline = $1);         # XXX
  177.         /:date "(\d+)"/ && ($date = $1, $hits++, &docdone);
  178.     }
  179.     &display;
  180.     print "</OL>";
  181.     close(WAISQ);
  182.     print "</DL>\n";
  183.  
  184.     print "</BODY>\n";
  185. }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. #
  192. # THis sub was set up to grab the context of the string.
  193. # It needs to be emplemented
  194. #
  195. sub display {
  196.     for ($i = 0; $i <= $length_context - 1; $i++ ) {
  197.     @tmp = split(/,/,@pcontext[$i]);
  198.     $href = @tmp[1];
  199.     $name = @tmp[0];
  200.     $filename = @tmp[4];
  201.     $test = @tmp[5];
  202.     $ext = @tmp[3];
  203.     $ii = $i+1;
  204.  
  205.         print "<td><A HREF=\"file:///tmp/httpd/.products/$name/$disc_name.frame.html\">";
  206.  
  207.         #$name =~ s/_/ /g; 
  208.  
  209.     print "<B><b>$ii. $real_name{$name} </b></a></td>";
  210.     print "<td><A HREF=\"$href\"><B><b>$filename</B></b></A></td>";
  211.         print "<td> $filetype{$ext} \n</td>";
  212.     print "<tr>";
  213.  
  214.     }
  215.     print "</table>";
  216.     print "</center>";
  217. }
  218.  
  219.  
  220. sub docdone {
  221.  
  222.     if ($headline =~ /Search produced no result/) {
  223.         print "<HR>";
  224.         print "<h2>Search produced no result.</h2>";
  225. #        print $headline, "<P>\n<PRE>";
  226. # the following was &'safeopen
  227. #        open(WAISCAT, "$waisd/$src.cat") || die "$src.cat: $!";
  228. #        while (<WAISCAT>) {
  229. #            s#(Catalog for database:)\s+.*#$1 <STRONG>Catalyst Catalog on $disc_name</STRONG>#;
  230. #            s#Headline:\s+(.*)#Headline: <A HREF="$1">$1</A>#;
  231. #            print;
  232. #        }
  233. #        close(WAISCAT);
  234. #        print "\n</PRE>\n";
  235.     } else {
  236.         $docname = $headline;
  237.     $docname =~ s/\.([^.]*)$//;
  238.     $extension= $1;
  239.     $docname =~ s/\/([^\/]*)$//;
  240.     $docname = $1;
  241.     $filename = $docname;
  242.     $docname = $1;
  243.     #$docname = $headline;
  244.            #$docname =~ s/\/([^\/]*)$//;
  245.  
  246.         $test = $headline;
  247.         $test =~ s/file:\/\///;
  248.            $test =~ s/\/([^\/]*)$//;
  249.  
  250.         if ($headline =~ /products\/.([^\/]*)\/index/) { $extension = "home"; }
  251.  
  252.     while ($test =~ /.products/) {
  253.     $filler = $docname;
  254.            $test =~ s/\/([^\/]*)$//;
  255.     $docname = $1;
  256.     }
  257.     $docname = $filler;
  258.     @context = ($docname,$headline,$filetype,$extension,$filename);
  259.     @pcontext[$hits] = join (",", @context); 
  260.     
  261.     }
  262.     $length_context = @pcontext;
  263.     
  264.     $score = $headline = $lines = $bytes = $type = $date = '';
  265. }
  266.  
  267. eval '&do_wais';
  268.